#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int runnian(int x)
{
	if (x % 400 == 0 ||( x % 4 == 0 && x % 100 !=0))
		return 1;
	else
		return 0;
}
int tianshu(int x, int y)
{
	int day_s[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	int jiajia = 0;
	int sum = 0;
	for (y; y >= 1; y--)
	{
		if (runnian(x) && y == 2)
		{
			day_s[y]++;
		}
		sum += day_s[y];
	}
	printf("%d", sum);
	return 0;
}
int main()
{
	int mon = 0;
	int year = 0;
	while (scanf("%d %d", &year, &mon) != EOF)
	{
		tianshu(year, mon);
	}
	return 0;
}